﻿using Microsoft.Xna.Framework;
using Rvz.Game.Main.Entities.Robots;
using Rvz.Game.Main.Entities.Zombies.States;
using Rvz.Game.Main.State;

namespace Rvz.Game.Main.Entities.Zombies
{
    public class Zombie : EntityBase<Zombie, ZombieStateBase>
    {
        private double _timeSinceLastAttacked;

        public Zombie(string contentManagerName)
            : base(contentManagerName)
        {
            IsActive = true;
            Damage = 10;
            Health = 20;
            MovementSpeed = .5f;
            AttackSpeed = 1;
        }

        public int Damage { get; set; }
        public int Health { get; set; }
        public float MovementSpeed { get; set; }
        public double AttackSpeed { get; set; }

        public void AttackRobot(Robot robot)
        {
            if (_timeSinceLastAttacked >= 0 && _timeSinceLastAttacked < AttackSpeed)
            { return; }

            robot.TakeDamage(Damage);
            _timeSinceLastAttacked = 0;
        }

        public override void HandleUpdate(GameState gameState, GameTime gameTime)
        {
            _timeSinceLastAttacked += gameTime.ElapsedGameTime.TotalSeconds;
        }

        public bool IsBrainDead()
        {
            return Health <= 0;
        }

        public bool IsActive { get; set; }

        protected override string SpriteFileLocation
        {
            get { return "Content\\Entities\\Zombies\\zombie_small.png"; }
        }

        public override void Destroy()
        {
            base.Destroy();
            IsActive = false;
        }
    }
}
